package JiHe;

import Arrays.YiChang.itheima.Student;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class CollectionTest2 {
    /*
    public Iterator<E> iterator():获取遍历集合的迭代器
     */
    public static void main(String[] args) {
        Collection<Student> c =new ArrayList<>();
        c.add(new Student("张三",23));
        c.add(new Student("李四",24));
        c.add(new Student("王五",25));

        //1、获取迭代器
        Iterator<Student> it = c.iterator();

//        Student stu1 = it.next();
//        System.out.println(stu1);
        while (it.hasNext()){
            Student stu = it.next();
            System.out.println(stu.getName()+"---"+stu.getAge());
        }

        for (Student s: c){
            System.out.println(s);
        }
        //foreach方法遍历集合
        c.forEach(student -> System.out.println(student));



    }
}
